Skip to content

Add --max-warnings option to fail test runs#14372

Open
miketheman wants to merge 1 commit intopytest-dev:mainfrom
miketheman:miketheman/max-warnings
Open

Add --max-warnings option to fail test runs#14372
miketheman wants to merge 1 commit intopytest-dev:mainfrom
miketheman:miketheman/max-warnings

Conversation

@miketheman
Copy link
Copy Markdown

Allow users to set a maximum number of allowed warnings via --max-warnings CLI option or max_warnings config option. When the warning count exceeds the threshold and all tests pass, pytest exits with a new WARNINGS_ERROR exit code (6). This supports gradually ratcheting down warnings in a codebase without converting them all to errors.

Based on the pytest-max-warnings plugin by @miketheman, with improvements: a dedicated ExitCode instead of an arbitrary exit code, and INI config support.

Closes #14371

Allow users to set a maximum number of allowed warnings via --max-warnings
CLI option or max_warnings config option. When the warning count exceeds
the threshold and all tests pass, pytest exits with a new WARNINGS_ERROR
exit code (6). This supports gradually ratcheting down warnings in a
codebase without converting them all to errors.

Based on the pytest-max-warnings plugin by @miketheman, with improvements:
a dedicated ExitCode instead of an arbitrary exit code, and INI config
support.

Closes pytest-dev#14371

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 8, 2026
:Exit code 3: Internal error happened while executing tests
:Exit code 4: pytest command line usage error
:Exit code 5: No tests were collected
:Exit code 6: Maximum number of warnings exceeded (see :option:`--max-warnings`)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debated on whether to add an explicit code, and since this doesn't match ExitCode 1, I chose to add another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide users a way to exit on error if exceeded the maximum configured warnings

1 participant